#pragma once
#include <iostream>
#include <cstdio>
#include "Protocol.hpp"

class Cal
{
    //加减乘除
    //自身写的类,不要去乱加const:因为自身并不一定总会实现const重载
public:
    Response Exe(Request& req)
    {
        Response res;
        int x = req.X(),y = req.Y(),num = 0;
        char oper = req.Oper();
        res.SetCode(1);
        // printf("%d %d %c\n",x,y,oper);
        switch(oper)
        {
            case '+':
                num = x + y;
                break;
            case '-':
                num = x - y;
                break;
            case '*':
                num = x * y;
                break;
            case '/':
            {
                if(y == 0)
                    res.SetCode(0);
                else
                    num = x / y;
                break;
            }
            default:
                res.SetCode(0);
                break;
        }
        if(res.Code())
            res.SetResult(num);
        
        return res;
    }
};